package monitor;


import java.util.HashMap;
import java.util.Map;
import java.util.Observable;

import exceptions.IncompatibleServerException;
import exceptions.ServerExistsException;

public class Monitor extends Observable {

	Map<ServerConnection, ServerMonitor> servers;

	public Monitor() {
		servers = new HashMap<ServerConnection, ServerMonitor>();
	}

	public void addServer(String host, int port) throws ServerExistsException,
			IncompatibleServerException {
		setChanged();
		ServerConnection sc = new ServerConnection(host, port);
		if (!servers.containsKey(sc)) {
			ServerMonitor monitor = new ServerMonitor(ServerStatus.REGISTERED, System.currentTimeMillis());
			servers.put(sc, monitor);
		} else {
			throw new ServerExistsException();
		}
		notifyObservers();
	}


}
